//
//  RecommendViewController.m
//  Journey
//
//  Created by dllo on 16/5/14.
//  Copyright © 2016年 dllo. All rights reserved.
//
#import "RecommendViewController.h"
#import "ScrollView.h"
#import "SubjectImageTableViewCell.h"
#import "RecommendTableViewCell.h"
#import "SubjectTextTableViewCell.h"
#import "DiscountImageTableViewCell.h"
#import "DiscountCollectionTableViewCell.h"
#import "DiscountTextTableViewCell.h"
#import "HotTravelTableViewCell.h"
#import "SSNetworking.h"
#import "RecommendModel.h"
#import "SlideModel.h"
#import "SubjectModel.h"
#import "Discount_subjectModel.h"
#import "DiscountModel.h"
#import "HotTravelModel.h"
#import "PicViewController.h"
#import "SubjectViewController.h"
#import "discountViewController.h"
#import "HotTravelViewController.h"
#import "SpecialViewController.h"
#import "PicViewController.h"
#import "packButtonViewController.h"
#import "YNDataReading.h"


static NSString *const recommendCell = @"RecommendCELL";
static NSString *const SubjectImageCell = @"ImageCELL";
static NSString *const SubjectTextCell = @"TextCELL";
static NSString *const DiscountImageCell = @"DiscountImageCELL";
static NSString *const DiscountCollectionCell = @"DiscountCollectionCELL";
static NSString *const DiscountTextCell = @"DiscountTextCELL";
static NSString *const HotTravelCell = @"HotTravelCELL";

@interface RecommendViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)BaseTableView *reTableView;
@property(nonatomic,strong)UIView *HeaderView;
@property(nonatomic,strong)NSMutableArray *allArray;
@property(nonatomic,strong)NSMutableArray *subArray;
@property(nonatomic,strong)NSMutableArray *slideArray;
@property(nonatomic,strong)NSMutableArray *discountSArray;
@property(nonatomic,strong)NSMutableArray *countArray;
@property(nonatomic,strong)NSMutableArray *hotArray;
@property(nonatomic,strong)NSMutableArray *slideUrl;
@property(nonatomic,strong)NSMutableArray *readArray;
//刷新
@property(nonatomic,assign)NSInteger nextPage; //记录下一页
@property(nonatomic,assign)BOOL isUpLoading;   //标记上下拉操作,yes上拉
//刷新图片数组
@property(nonatomic,strong)NSMutableArray *imageArray;

@end

@implementation RecommendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
   // self.navigationController.navigationBarHidden = NO;
 //   [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"btn_actionsheet"] forBarMetrics:UIBarMetricsDefault];
    
    self.navigationController.navigationBar.dk_barTintColorPicker = DKColorPickerWithRGB(0x139a43,0x4F4F4F);
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(150 * WIDTHC, 0, 100 * WIDTHC, 44 * WIDTHC)];
    title.text = @"推  荐";
    title.textAlignment = NSTextAlignmentCenter;
    title.dk_textColorPicker = DKColorPickerWithRGB(0x1C1C1C,0xE8E8E8);
    
    self.navigationItem.titleView = title;
 //   self.navigationItem.hidesBackButton = NO;
    
    self.navigationController.navigationBar.translucent = NO;
    
    //self.automaticallyAdjustsScrollViewInsets =NO;
    
    
    
    self.allArray = [NSMutableArray array];
    self.subArray = [NSMutableArray array];
    self.slideArray = [NSMutableArray array];
    self.discountSArray = [NSMutableArray array];
    self.countArray = [NSMutableArray array];
    self.hotArray = [NSMutableArray array];
    self.slideUrl = [NSMutableArray array];
    
 
   
    
    //创建tableView
    self.reTableView = [[BaseTableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
    [self.view addSubview:self.reTableView];
    self.reTableView.delegate = self;
    self.reTableView.dataSource = self;
    //注册SubjectView
    [self.reTableView registerClass:[RecommendTableViewCell class] forCellReuseIdentifier:recommendCell];
    [self.reTableView registerClass:[SubjectImageTableViewCell class] forCellReuseIdentifier:SubjectImageCell];
    [self.reTableView registerClass:[SubjectTextTableViewCell class] forCellReuseIdentifier:SubjectTextCell];
    //注册DiscountView
    [self.reTableView registerClass:[DiscountImageTableViewCell class] forCellReuseIdentifier:DiscountImageCell];
    [self.reTableView registerClass:[DiscountCollectionTableViewCell class] forCellReuseIdentifier:DiscountCollectionCell];
    [self.reTableView registerClass:[DiscountTextTableViewCell class] forCellReuseIdentifier:DiscountTextCell];
    //注册HotTravelView
    [self.reTableView registerClass:[HotTravelTableViewCell class] forCellReuseIdentifier:HotTravelCell];
    self.reTableView.showsVerticalScrollIndicator = NO;
    //添加头视图
    self.HeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 350 * WIDTHC)];
  //  self.HeaderView.backgroundColor = [UIColor clearColor];
    self.HeaderView.dk_backgroundColorPicker = DKColorPickerWithRGB(0xFFFFFF,0x363636);
    self.reTableView.tableHeaderView = self.HeaderView;
     [self getButton];
    
    //加载条
    //显示
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
     [self getData];
    self.imageArray = [NSMutableArray array];
    for (int i = 1; i < 4; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"loading_0%d",i]];
        [self.imageArray addObject:image];
    }
    //打开数据库
    [[DataBaseHandle shareDataBaseHandle] hotOpenDB];
    [[DataBaseHandle shareDataBaseHandle] hotCreatTable];
    
    self.isUpLoading = NO;
    [self addFooter];
    [self addHeader];
    
    
 }

#pragma mark --下拉刷新
-(void)addHeader{
    //block中不能使用self,会报错
    __block RecommendViewController *recommendVC = self;
    
    MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
        //记录页码
        recommendVC.nextPage = 1;
        //标记下拉刷新
        recommendVC.isUpLoading = NO;
        //请求数据
        [recommendVC getHotDataList:recommendVC.nextPage];
        
    }];
    //普通闲置状态
    [header setImages:self.imageArray forState:MJRefreshStateIdle];
    //松开就可以进行刷新的状态
    [header setImages:self.imageArray forState:MJRefreshStatePulling];
    //正在刷新中的状态
    [header setImages:self.imageArray forState:MJRefreshStateRefreshing];
    
    self.reTableView.mj_header = header;
}

#pragma mark -- 上拉加载更多
-(void)addFooter{
    
    __block RecommendViewController *recommendVC = self;
    //添加上拉刷新尾部控件
    
    MJRefreshAutoGifFooter *footer = [MJRefreshAutoGifFooter footerWithRefreshingBlock:^{
        //上拉一次自增一次
        recommendVC.nextPage ++;
        //标记为上拉操作
        recommendVC.isUpLoading = YES;
        //请求数据
        [recommendVC getHotDataList:recommendVC.nextPage];
        
        
        

    }];
    
    [footer setImages:self.imageArray forState:MJRefreshStateRefreshing];
    self.reTableView.mj_footer = footer;
    
}


//点击方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            SubjectViewController *subVC = [[SubjectViewController alloc] init];
            UINavigationController *subNa = [[UINavigationController alloc] initWithRootViewController:subVC];
            SubjectModel *subModel = [self.subArray firstObject];
            subVC.navigationItem.title = subModel.title;
            subVC.substring = subModel.url;
            [self presentViewController:subNa animated:YES completion:^{
            }];
        }
        if (indexPath.row == 2) {
            SpecialViewController *special = [[SpecialViewController alloc] init];
            UINavigationController *specNa = [[UINavigationController alloc] initWithRootViewController:special];
            [self presentViewController:specNa animated:YES completion:^{
                
                
            }];
        }
    }
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            discountViewController *disVC = [[discountViewController alloc] init];
            UINavigationController *disNa = [[UINavigationController alloc] initWithRootViewController:disVC];
            Discount_subjectModel *discount = [self.discountSArray firstObject];
            disVC.navigationItem.title = discount.title;
            disVC.disString = discount.url;
            [self presentViewController:disNa animated:YES completion:^{
            }];
        }
        if (indexPath.row == 2){
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"数据维护!" message:nil preferredStyle:UIAlertControllerStyleAlert];
            
            [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
            [self presentViewController:alert animated:YES completion:nil];
            
        }
     }
    
    
       if (indexPath.section == 2) {
        HotTravelViewController *hotVC = [[HotTravelViewController alloc] init];
        UINavigationController *hotNa = [[UINavigationController alloc] initWithRootViewController:hotVC];
        HotTravelModel *hotModel = [self.hotArray objectAtIndex:indexPath.row];
        hotVC.hotString = hotModel.view_url;
           hotVC.navigationItem.title = hotModel.title;
      //  NSLog(@"%@",hotModel.view_url);
        [self presentViewController:hotNa animated:YES completion:^{
        }];
    }
}


-(void)getData
{
   
    
    //GET请求
    [SSNetworking ssGETWithURL:@"http://open.qyer.com/qyer/recommands/entry?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&lat=38.88256929626057&lon=121.5393328309779&page=1&track_app_channel=App%2520Store&track_app_version=6.8.5&track_device_info=iPhone%25205s&track_deviceid=CBF73BD2-C65E-4BC1-9574-89BDE1EE9C36&track_os=ios%25209.2.1&v=1" parameter:nil success:^(id result) {
        

        //加入缓存
        [[YNDataReading shareYNataReading]writeCachePlist:@"recommend" result:result];
       
        //读取数据
        NSDictionary *dic = [[YNDataReading shareYNataReading] readCachePlist:@"recommend"];
       
        NSDictionary *dataDic = [dic objectForKey:@"data"];
        
        if (self.isUpLoading == NO) {
            [self.allArray removeAllObjects];
           
        }
        //KVC赋值®
        RecommendModel *recommend = [[RecommendModel alloc] init];
        [recommend setValuesForKeysWithDictionary:dataDic];
        [self.allArray addObject:recommend];
        //轮播图赋值
        for (SlideModel *slide in recommend.slide) {
            // NSLog(@"%@",slide);
            [self.slideArray addObject:slide.photo];
            [self.slideUrl addObject:slide.url];
        }
        
        //轮播图方法
        [self getScrollViewData];
        //subject赋值
        self.subArray = [NSMutableArray  arrayWithArray:recommend.subject];
        self.discountSArray = [NSMutableArray arrayWithArray:recommend.discount_subject];
        self.countArray = [NSMutableArray arrayWithArray:recommend.discount];
        
        
        //隐藏加载条
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        
        [self.reTableView reloadData];
        
    } failure:^(NSError *error) {
        
        
    } network:^(BOOL network) {
       
       
        NSDictionary *dic = [[YNDataReading shareYNataReading] readCachePlist:@"recommend"];
         //隐藏加载条
     
    
        NSDictionary *dataDic = [dic objectForKey:@"data"];
        //KVC赋值®
        RecommendModel *recommend = [[RecommendModel alloc] init];
        [recommend setValuesForKeysWithDictionary:dataDic];
        [self.allArray addObject:recommend];
        //轮播图赋值
        for (SlideModel *slide in recommend.slide) {
            // NSLog(@"%@",slide);
            [self.slideArray addObject:slide.photo];
            [self.slideUrl addObject:slide.url];
        }
        
        //轮播图方法
        [self getScrollViewData];
        //subject赋值
        self.subArray = [NSMutableArray  arrayWithArray:recommend.subject];
        self.discountSArray = [NSMutableArray arrayWithArray:recommend.discount_subject];
        self.countArray = [NSMutableArray arrayWithArray:recommend.discount];
        
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        [self.reTableView reloadData];
        
    }];
     
}
//hotTravel
-(void)getHotDataList:(NSInteger) nextPage{
    
    [SSNetworking ssGETWithURL:@"http://open.qyer.com/qyer/recommands/trip?client_id=qyer_android&client_secret=9fcaae8aefc4f9ac4915&v=1&track_deviceid=867323023990045&track_app_version=6.7.1&track_app_channel=xiaomi&track_device_info=cancro&track_os=Android4.4.4&app_installtime=1443411950696&lat=38.883872&lon=121.544701&type=index&page=2&count=10" parameter:nil success:^(id result) {
        
        [[YNDataReading shareYNataReading]writeCachePlist:@"hotTravel" result:result];
        
        NSDictionary *hdic = [[YNDataReading shareYNataReading]readCachePlist:@"hotTravel"];
        
        NSArray *hotDataArray = [hdic objectForKey:@"data"];
        
               for (NSDictionary *hotDataDic in hotDataArray) {
            HotTravelModel *hotModel = [[HotTravelModel alloc] init];
            [hotModel setValuesForKeysWithDictionary:hotDataDic];
            
            [self.hotArray addObject:hotModel];
            // NSLog(@"%@",hotModel.view_url);
            //  NSLog(@"--%@",self.hotArray);
        }
        
        //停止刷新
        [self.reTableView.mj_footer endRefreshing];
        [self.reTableView.mj_header endRefreshing];
        
        
        [self.reTableView reloadData];
        
    } failure:^(NSError *error) {
        
        
    } network:^(BOOL networking) {
       

        //停止刷新
        [self.reTableView.mj_footer endRefreshing];
        [self.reTableView.mj_header endRefreshing];
        
        NSDictionary *hdic = [[YNDataReading shareYNataReading]readCachePlist:@"hotTravel"];
        
        NSArray *hotDataArray = [hdic objectForKey:@"data"];
        
        for (NSDictionary *hotDataDic in hotDataArray) {
            HotTravelModel *hotModel = [[HotTravelModel alloc] init];
            [hotModel setValuesForKeysWithDictionary:hotDataDic];
            
            [self.hotArray addObject:hotModel];
            // NSLog(@"%@",hotModel.view_url);
            //  NSLog(@"--%@",self.hotArray);
        }
        
        
        
        
        [self.reTableView reloadData];
        
    }];
    
  }
//轮播图
-(void)getScrollViewData
{
    ScrollView *myscrollView = [[ScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200 * WIDTHC)];
    [myscrollView setImages:self.slideArray];
    __block RecommendViewController *recomVC = self;
   [ myscrollView setTapBlock:^(NSInteger index) {
        PicViewController *picVC = [[PicViewController alloc] init];
       UINavigationController *picNa = [[UINavigationController alloc] initWithRootViewController:picVC];
        picVC.slideString = [recomVC.slideUrl objectAtIndex:index];
       [recomVC presentViewController:picNa animated:YES completion:^{
       }];
   }];

     [self.HeaderView addSubview:myscrollView];
}

//改变分区颜色
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
    // Background color
  
    view.dk_tintColorPicker = DKColorPickerWithRGB(0xF5F5F5,0x363636);
    // Text Color
    UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
    
    [header.textLabel setTextColor:[UIColor blackColor]];
    
}



//分区标题高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 50 * WIDTHC;
}

//分区标题
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return @"发现下一站";
    } else if(section == 1){
        return @"抢特价折扣";
    }
        return @"看热门游记";
}
//分区数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if (self.allArray.count == 0) {
        return 2;
    }
    return 3;
}

//cell高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row == 2) {
            return 50 * WIDTHC;
        }
    }
     if (indexPath.section == 1) {
        if (indexPath.row == 1) {
            return 400 * WIDTHC;
        }else if(indexPath.row == 2){
            return 50 * WIDTHC;
        }
    }
    if (indexPath.section == 2) {
        return 100 * WIDTHC;
    }
    return 150 * WIDTHC;
}
//cell个数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 2) {
        return self.hotArray.count;
    }
    return 3;
}

//cell对象
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if(indexPath.section == 0){
    if (indexPath.row == 0) {
        SubjectImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SubjectImageCell];
    
        SubjectModel *subModel = [self.subArray firstObject];
      //  NSLog(@"---%@",self.subArray);
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.subModel = subModel;
        
        return cell;
        
    } else if(indexPath.row == 1){
        RecommendTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:recommendCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.tempArray = self.subArray;
         __block RecommendViewController *recomVC = self;
        [cell setSubjectBlock:^(NSInteger index) {
            SubjectViewController *subVC = [[SubjectViewController alloc] init];
            UINavigationController *subNa = [[UINavigationController alloc] initWithRootViewController:subVC];
            SubjectModel *subject = [self.subArray objectAtIndex:index];
            subVC.substring = subject.url;
            [recomVC presentViewController:subNa animated:YES completion:^{
          }];
        }];
          return cell;
    }
    SubjectTextTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SubjectTextCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    }else if(indexPath.section == 1){
        if (indexPath.row == 0) {
            DiscountImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:DiscountImageCell];
           Discount_subjectModel *dismodel = [self.discountSArray firstObject];
            cell.disModel = dismodel;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        } else if(indexPath.row == 1){
            DiscountCollectionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:DiscountCollectionCell];
            cell.allcountArray = self.countArray;
            
            [cell setDiscountBlock:^(NSInteger index) {
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"数据维护!" message:nil preferredStyle:UIAlertControllerStyleAlert];
                
                [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
                [self presentViewController:alert animated:YES completion:nil];
              
            }];
            
            
            
             cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }
        DiscountTextTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:DiscountTextCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    HotTravelTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:HotTravelCell];
    HotTravelModel *hotModel = [self.hotArray objectAtIndex:indexPath.row];
    cell.hotmodel = hotModel;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
   
    
    return cell;
}



-(void)getButton{
    UIButton *packButton = [UIButton buttonWithType:UIButtonTypeCustom];
    packButton.frame = CGRectMake(20 * WIDTHC, 210 * WIDTHC, 70 * WIDTHC, 70 * WIDTHC);
    [packButton setImage:[UIImage imageNamed:@"button1"] forState:UIControlStateNormal];
    [self.HeaderView addSubview:packButton];
    [packButton addTarget:self action:@selector(packBottonAction:) forControlEvents:UIControlEventTouchUpInside];
    UILabel *packLabel = [[UILabel alloc]initWithFrame:CGRectMake(20 * WIDTHC, 280 * WIDTHC, 70 * WIDTHC, 20 * WIDTHC)];
    packLabel.text = @"看锦囊";
    packLabel.textAlignment = NSTextAlignmentCenter;
    packLabel.font = [UIFont systemFontOfSize:16];
    packLabel.textColor = [UIColor grayColor];
    [self.HeaderView addSubview:packLabel];
 
    UIButton *discountButton = [UIButton buttonWithType:UIButtonTypeCustom];
    discountButton.frame = CGRectMake(120 * WIDTHC, 210 * WIDTHC, 70 * WIDTHC, 70 *WIDTHC);
    [discountButton setImage:[UIImage imageNamed:@"button2"] forState:UIControlStateNormal];
    [discountButton addTarget:self action:@selector(discountButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.HeaderView addSubview:discountButton];
    UILabel *discountLabel = [[UILabel alloc]initWithFrame:CGRectMake(120 *WIDTHC, 280 * WIDTHC, 70 * WIDTHC, 20 *WIDTHC)];
    discountLabel.text = @"抢折扣";
    discountLabel.textAlignment = NSTextAlignmentCenter;
    discountLabel.font = [UIFont systemFontOfSize:16];
    discountLabel.textColor = [UIColor grayColor];
    [self.HeaderView addSubview:discountLabel];
    
    UIButton *wineshopButton = [UIButton buttonWithType:UIButtonTypeCustom];
    wineshopButton.frame = CGRectMake(220 * WIDTHC, 210 *WIDTHC, 70 *WIDTHC, 70 * WIDTHC);
    [wineshopButton setImage:[UIImage imageNamed:@"button3"] forState:UIControlStateNormal];
    [wineshopButton addTarget:self action:@selector(wineshopButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.HeaderView addSubview:wineshopButton];
    UILabel *wineshopLabel = [[UILabel alloc]initWithFrame:CGRectMake(220 * WIDTHC, 280 * WIDTHC, 70 * WIDTHC, 20 * WIDTHC)];
    wineshopLabel.text = @"订酒店";
    wineshopLabel.textAlignment = NSTextAlignmentCenter;
    wineshopLabel.font = [UIFont systemFontOfSize:16];
    wineshopLabel.textColor = [UIColor grayColor];
    
    [self.HeaderView addSubview:wineshopLabel];
    
   
    UIButton *tripButton = [UIButton buttonWithType:UIButtonTypeCustom];
    tripButton.frame = CGRectMake(320 * WIDTHC, 210 * WIDTHC, 70 * WIDTHC, 70 * WIDTHC);
    [tripButton setImage:[UIImage imageNamed:@"button4"] forState:UIControlStateNormal];
    
    [tripButton addTarget:self action:@selector(tripButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.HeaderView addSubview:tripButton];
    UILabel *tripLabel = [[UILabel alloc]initWithFrame:CGRectMake(320 * WIDTHC, 280 * WIDTHC, 70 * WIDTHC, 20 * WIDTHC)];
    tripLabel.text = @"旅途中";
    tripLabel.textAlignment = NSTextAlignmentCenter;
    tripLabel.font = [UIFont systemFontOfSize:16];
    tripLabel.textColor = [UIColor grayColor];
    [self.HeaderView addSubview:tripLabel];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 300 * WIDTHC, self.HeaderView.frame.size.width, 50 * WIDTHC);
   // button.backgroundColor = [UIColor redColor];
    [button setTitle:@"点评我去过的目的地, 帮助更多穷游er         >" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(tripButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    button.titleLabel.font = [UIFont systemFontOfSize:16];
    [self.HeaderView addSubview:button];
}

//section跟tableView一起滚动的方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == self.reTableView)
    {
        CGFloat sectionHeaderHeight = 50;
        if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0)
        {
            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y,0, 0, 0);
        } else if (scrollView.contentOffset.y>=sectionHeaderHeight)
        {
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
        }
    }
}

-(void)packBottonAction:(UIButton *)button{
    packButtonViewController *packButton = [[packButtonViewController alloc] init];
    UINavigationController *packNa = [[UINavigationController alloc] initWithRootViewController:packButton];
    [self presentViewController:packNa animated:YES completion:^{
        
        
    }];
}


-(void)discountButtonAction:(UIButton *)button{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"数据维护!" message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
    [self presentViewController:alert animated:YES completion:nil];
}

-(void)wineshopButtonAction:(UIButton *)button{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"数据维护!" message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
    [self presentViewController:alert animated:YES completion:nil];
}


-(void)tripButtonAction:(UIButton *)button
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"数据维护!" message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
    [self presentViewController:alert animated:YES completion:nil];
}

@end
